﻿// Write a program that calculates the greatest common divisor (GCD) of given two numbers. 
// Use the Euclidean algorithm (find it in Internet).
// For 1071 and 1029 the GCD is 21

using System;

class FindGCDof2Numbers
{
    static void Main()
    {
        Console.Write("Enter X : ");
        int numberX = int.Parse(Console.ReadLine());
        Console.Write("Enter Y : ");
        int numberY = int.Parse(Console.ReadLine());

        if (numberX == 0 && numberY == 0)
        {
            Console.WriteLine("Both numbers are 0.");
        }
        else if (numberX == 0)
        {
            Console.WriteLine("The GCD is {0}", numberY);
        }
        else if (numberY == 0)
        {
             Console.WriteLine("The GCD is {0}", numberX);
        }
        else
        {
            while (numberX != numberY)
            {
                if (numberX > numberY)
                {
                    numberX = numberX - numberY;
                }
                else
                {
                    numberY = numberY - numberX;
                }
            }
            Console.WriteLine("The GCD of both numbers is {0}", numberX);
        }
    }
}
